package com.chaopei.msiteadmin.controller;

import com.chaopei.msiteadmin.service.ProductService;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author Corday 天涯
 * @Date 2022/5/17 14:30
 */
@RestController
public class ProductController {
    @Resource
    private ProductService productService;
    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;
    /**
     *  更新数据库,同时发消息
     *  http://localhost:5508/go?name=热门
     * @param
     * @return
     */
    @RequestMapping("/go")
    public String go(String name){
        String info="";
        //jmsMessagingTemplate.convertAndSend("product.msg","ok");
        info= productService.updateProduct(name);
        if("success".equals(info)){
            //要处理异常
            jmsMessagingTemplate.convertAndSend("product.msg","ok");
        }
      return info;
    }
}